package com.treeroot.uploadservice.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Description:
 * @Author:treeRoot
 * @Email:553503639@qq.com
 * @Date: Create in 13:52 / 2022/5/5
 */
//当项目已启动, spring接口, spring加载之后,执行接口一个方法
@Component
//    读取配置文件内容
public class MyConfig implements WebMvcConfigurer {
    @Value("${yuan.file.root.path}")
    public  String fileRootPath;

    /**
     * 资源映射:把请求的/archive/** 映射到该文件根路径
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/archive/**").addResourceLocations("file:" + fileRootPath);
    }

}
